//
//  LGRecommendDoctorCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/23.
//  推荐医生

#import "LGRecommendDoctorCell2.h"

@interface LGRecommendDoctorCell2()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)CAGradientLayer *gradientLayer;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**   */
@property (nonatomic , strong)UIImageView *headPic;
/**   */
@property (nonatomic , strong)UILabel *docNameLabel;
/**   */
@property (nonatomic , strong)UILabel *postTitleLabel;
/**   */
@property (nonatomic , strong)UILabel *hospitalLabel;
/**   */
@property (nonatomic , strong)UIView *bottomView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UILabel *descLabel;
/**   */
@property (nonatomic , strong)UIButton *touchBtn;
/**   */
@property (nonatomic , strong)LGCustomCellData *cellData;
/**   */
@property (nonatomic , copy)NSString *doctorId;
@end

@implementation LGRecommendDoctorCell2

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    [super setDataDic:dataDic];
    self.bubbleView.image = self.receiverBubble;
    NSDictionary *contentDic = [ObjectTool jsonToObject:dataDic[@"content"][@"ext"]];
    NSDictionary *patientDic = contentDic[@"msgcontent_doctor"];
    self.doctorId = LGNSString(contentDic[@"bus_id"]);
    self.titleLabel.text = LGNSString(patientDic[@"title"]);
    [self.headPic sd_setImageWithURL:[NSURL URLWithString:patientDic[@"avatar"]]];
    self.docNameLabel.text = LGNSString(patientDic[@"name"]);
    self.postTitleLabel.text = LGNSString(patientDic[@"job"]);
    self.hospitalLabel.text = LGNSString(patientDic[@"hospital"]);
    CGFloat width = [LGNSString(patientDic[@"job"]) textWidthWithFont:LGFontWeight(12, UIFontWeightMedium) maxHeight:MAXFLOAT];
    [self.postTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(width+15));
    }];
    [self.bubbleView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(Screen_W-viewPix(100)));
    }];
}



//查看医生详情
-(void)checkDoctorDetailAction{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CheckDoctorDetail2" object:nil userInfo:@{@"doctorId":self.doctorId}];
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.bubbleView addSubview:self.baseView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.headPic];
    [self.baseView addSubview:self.docNameLabel];
    [self.baseView addSubview:self.postTitleLabel];
    [self.baseView addSubview:self.hospitalLabel];
    [self.baseView addSubview:self.touchBtn];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.equalTo(self.bubbleView);
        make.width.equalTo(@(Screen_W-viewPix(100)));
    }];
    [self.docNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headPic.mas_right).offset(viewPix(12));
        make.top.equalTo(self.headPic);
        make.height.equalTo(@(viewPix(22)));
    }];
    [self.postTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.docNameLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.docNameLabel);
        make.width.equalTo(@(viewPix(70)));
        make.height.equalTo(@(viewPix(18)));
    }];
    [self.hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.docNameLabel.mas_bottom).offset(viewPix(6));
        make.left.equalTo(self.docNameLabel);
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.height.equalTo(@(20));
    }];
//    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.iconView.mas_right).offset(viewPix(7));
//        make.top.equalTo(self.bottomView).offset(viewPix(8));
//        make.right.equalTo(self.bottomView).offset(-viewPix(5));
//    }];
    [self.touchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(self.baseView);
    }];
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(CAGradientLayer *)gradientLayer{
    if(!_gradientLayer){
        _gradientLayer = [[CAGradientLayer alloc]init];
        _gradientLayer.startPoint = CGPointMake(0.5, 0);
        _gradientLayer.endPoint = CGPointMake(0.5, 1);
        _gradientLayer.colors = @[(__bridge id)[UIColor colorWithString:@"#E4F2FF"].CGColor, (__bridge id)[UIColor colorWithString:@"#FFFFFF"].CGColor];
        _gradientLayer.locations = @[@(0), @(1.0f)];
    }
    return _gradientLayer;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _titleLabel.frame = CGRectMake(viewPix(12), viewPix(10), Screen_W-viewPix(124), viewPix(20));
    }
    return _titleLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(viewPix(12), viewPix(40), Screen_W-viewPix(124), 0.5)];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView;
}

-(UIImageView *)headPic{
    if(!_headPic){
        _headPic = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(12), kMaxY(self.lineView.frame)+viewPix(12), viewPix(46), viewPix(46))];
        _headPic.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
        _headPic.cornerRidus = 5;
    }
    return _headPic;
}

-(UILabel *)docNameLabel{
    if(!_docNameLabel){
        _docNameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _docNameLabel;
}

-(UILabel *)postTitleLabel{
    if(!_postTitleLabel){
        _postTitleLabel = [UILabel lableWithText:@"" colorString:@"#56BEA0" textFont:LGFontWeight(12, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _postTitleLabel.backgroundColor = [UIColor colorWithString:@"#EBF8F3"];
        _postTitleLabel.cornerRidus = viewPix(9);
    }
    return _postTitleLabel;
}

-(UILabel *)hospitalLabel{
    if(!_hospitalLabel){
        _hospitalLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _hospitalLabel;
}

-(UIView *)bottomView{
    if(!_bottomView){
        _bottomView = [[UIView alloc] initWithFrame:CGRectMake(viewPix(12), kMaxY(self.lineView.frame)+viewPix(70), Screen_W-viewPix(124), viewPix(54))];
        _bottomView.backgroundColor = [UIColor colorWithString:@"#F7F9FB"];
    }
    return _bottomView;
}


-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"聊天咨询-推荐擅长"]];
        _iconView.frame = CGRectMake(viewPix(6), viewPix(9), viewPix(35), viewPix(15));
    }
    return _iconView;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:2];
    }
    return _contentLabel;
}

-(UIButton *)touchBtn{
    if(!_touchBtn){
        _touchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_touchBtn addTarget:self action:@selector(checkDoctorDetailAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _touchBtn;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
